const { userModel } = require('./models/usersModel')
const { studentsModel } = require('./models/studentsModel')

// 持久层
module.exports.login = function (user) {
  const result = userModel.find(user)
  
  return result
}

module.exports.register = async function (registerInfo) {
  const userInfo = {
    username: registerInfo.username,
    password: registerInfo.password
  }
  const studentInfo = {
    name: registerInfo.name,
    age: registerInfo.age,
    gender: registerInfo.gender
  }
  const userResult = await userModel.create(userInfo)
  const studentResult = await studentsModel.create(studentInfo)

  if (userResult._id === undefined && studentResult._id === undefined) {
    registerResult = false
  } else {
    registerResult = true
  }

  return registerResult
}